const webpack = require('webpack')
const path = require('path');
const { config } = require('process');
const px2rem = require('postcss-px2rem-exclude')
const postcss = px2rem({
  // 基准大小 baseSize，需要和rem.js中相同
  remUnit: 16,
  exclude: '/node_modules/i'
})
function resolve (dir) {
    return path.join(__dirname, dir)
}
module.exports = {
  publicPath: './',
  css: {
    loaderOptions: {
      less: {
        lessOptions: {
          modifyVars: {
            'primary-color': '#27BFA3',
            'error-color': '#FF4500'
          },
          javascriptEnabled: true,
        },
      },
    },
  },
  chainWebpack: config => {
    config.resolve.alias
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))

    config.module
      .rule('images')
      .test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
      .use('image-webpack-loader')
        .loader('image-webpack-loader')
        .options({
          bypassOnDebug: true
        })
        .end()
  },
  configureWebpack: config => {
    /**
     *  添加分析工具
     */
    if (process.env.NODE_ENV === "production") {
      if (process.env.npm_config_report) {
        config
          .plugin("webpack-bundle-analyzer")
          .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin)
          .end();
        config.plugins.delete("prefetch");
      }
    }
  },

  configureWebpack: {
    plugins: [
      new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
    ],
    externals: {
      'BMap': 'BMap' // 高德地图配置
    }
  },
  productionSourceMap: false,

  devServer: {
      port: 8080,
      // host: "0.0.0.0",
      host: "localhost",
      https: true,
      proxy: {
          "/api": {
              target: "https://newyxp.sse100.com/", // 预发
              changeOrigin: true,
              pathRewrite: {
                  "^/api": "/api"
              }
          }
      }
  },
}
